Skip to content

docs: Document extension framework debugging, env propagation, and error handling#6860

Open
Copilot wants to merge 2 commits intomainfrom
copilot/update-extension-framework-docs
Open

docs: Document extension framework debugging, env propagation, and error handling#6860
Copilot wants to merge 2 commits intomainfrom
copilot/update-extension-framework-docs

Conversation

Copy link
Contributor

Copilot AI commented Feb 24, 2026

Fixes #6863

extension-framework.md was missing documentation for several shipped features identified as pain points in real-world extension development (#6853).

Changes

  • Debugging Extensions — New section covering:

    • AZD_EXT_DEBUG / AZD_EXT_TIMEOUT for lifecycle/listen extensions
    • azdext.WaitForDebugger(ctx, azdClient) for custom extension commands; documents ErrDebuggerAborted and context.Canceled return values
  • Invoking Extension Commands — Replaces vague "additional env vars are set" with precise behavior split by execution path:

    • Custom commands inherit full os.Environ() + AZD_SERVER, AZD_ACCESS_TOKEN, TRACEPARENT/TRACESTATE, FORCE_COLOR, COLUMNS
    • Lifecycle/listen commands receive only the explicitly set vars above; global flags (--debug, --no-prompt, --cwd, -e) are not forwarded as env vars
    • Reference table for AZD_EXT_DEBUG and AZD_EXT_TIMEOUT with defaults
  • EnvironmentServiceGetValues, GetValue, SetValue: env_name/name is optional; omitting it resolves to the current/default environment (shipped in Make env_name optional in EnvironmentService gRPC methods #6733, undocumented until now)

  • Structured Error Handling — New section on azdext.ServiceError, and clarifying that WrapError/UnwrapError are internal; extension authors return *azdext.ServiceError from provider methods and Azure SDK azcore.ResponseError values are auto-detected

  • Table of Contents — Updated to surface the new sections


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

… EnvironmentService

Co-authored-by: kristenwomack <5034778+kristenwomack@users.noreply.github.com>
Copilot AI changed the title [WIP] Update documentation for new features in extension framework docs: Update extension framework documentation for debugging, environment propagation, and error handling Feb 24, 2026
Copilot AI requested a review from kristenwomack February 24, 2026 02:08
Copilot AI changed the title docs: Update extension framework documentation for debugging, environment propagation, and error handling docs: Document extension framework debugging, env propagation, and error handling Feb 24, 2026
@kristenwomack kristenwomack linked an issue Feb 24, 2026 that may be closed by this pull request
10 tasks
@microsoft-github-policy-service microsoft-github-policy-service bot added the no-recent-activity identity issues with no activity label Mar 3, 2026
@spboyer
Copy link
Member

spboyer commented Mar 5, 2026

This PR addresses #6863 — documenting extension framework debugging, env propagation, and error handling.

Fixes #6863

@microsoft-github-policy-service microsoft-github-policy-service bot removed the no-recent-activity identity issues with no activity label Mar 5, 2026
@kristenwomack kristenwomack marked this pull request as ready for review March 6, 2026 01:19
Copilot AI review requested due to automatic review settings March 6, 2026 01:19
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the extension framework documentation to reflect recently shipped extension SDK behaviors around debugging, environment-variable propagation, optional environment targeting in EnvironmentService, and structured error transmission between azd and extensions.

Changes:

  • Adds new sections for Distributed Tracing, Debugging Extensions, Invoking Extension Commands, and Structured Error Handling.
  • Documents AZD_EXT_DEBUG / AZD_EXT_TIMEOUT and azdext.WaitForDebugger() behavior and return values.
  • Clarifies EnvironmentService GetValues/GetValue/SetValue semantics when environment name is omitted/empty.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 1627 to 1629
- **Request:** _GetEnvironmentRequest_
- `name` (string)
- `name` (string, optional) — if omitted or empty, the current/default environment is used
- **Response:** _KeyValueListResponse_
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GetEnvironmentRequest is used by both EnvironmentService.Get and GetValues. Only GetValues treats an empty name as “use current/default” (Get still calls envManager.Get and will fail on empty). Marking name as “optional” here can be misleading—consider clarifying that this empty/omitted behavior applies to GetValues specifically (and Get still requires a name).

Copilot uses AI. Check for mistakes.

// Pause here when AZD_EXT_DEBUG=true to allow debugger attachment.
// Returns nil if AZD_EXT_DEBUG is not set or if user confirms debugger is attached.
// Returns azdext.ErrDebuggerAborted if user cancels the debug prompt.
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the WaitForDebugger() sample comments, azdext.ErrDebuggerAborted is described as happening when the user “cancels” the debug prompt, but the implementation returns ErrDebuggerAborted only when the user declines (selects “N”). Cancellation (Ctrl+C) maps to context.Canceled. Please adjust the comment to match the actual return semantics so readers handle the right error cases.

Suggested change
// Returns azdext.ErrDebuggerAborted if user cancels the debug prompt.
// Returns azdext.ErrDebuggerAborted if the user declines (answers "No") to the debug prompt.
// Cancellation via Ctrl+C will surface as context.Canceled.

Copilot uses AI. Check for mistakes.
Comment on lines 1178 to +1184
- An environment variable named `AZD_SERVER` is set with the server address and random port (e.g., `localhost:12345`).
- An `azd` access token environment variable `AZD_ACCESS_TOKEN` is set which is a JWT token signed with a randomly generated key good for the lifetime of the command. The token includes claims that identify each unique extensions and its supported capabilities.
- Additional environment variables from the current `azd` environment are also set.
- `TRACEPARENT` and `TRACESTATE` are set when a distributed trace context is active, allowing extensions to participate in the same trace as the parent `azd` process.
- `FORCE_COLOR=1` is set when the parent terminal supports color output.
- `COLUMNS` is set to the current terminal width.
- For **custom extension commands** (e.g., `azd myext mycommand`): the full parent process environment (`os.Environ()`) is inherited, plus the variables above.
- For **lifecycle/listen commands** (e.g., `listen`): only the explicitly set variables above are provided — global flags such as `--debug`, `--no-prompt`, `--cwd`, and `-e/--environment` are **not** automatically forwarded as environment variables. The `--debug` flag is forwarded as a command-line argument to the `listen` command.
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This env-var propagation list doesn’t match current behavior. COLUMNS is set for custom extension commands (see cmd/extensions.go) but is not set for lifecycle/listen extensions (cmd/middleware/extensions.go only sets AZD_SERVER/AZD_ACCESS_TOKEN/FORCE_COLOR + trace env). Also, custom commands append the active azd environment variables via env.Environ() in addition to os.Environ(), which isn’t captured here. Please update the bullets to accurately reflect the two execution paths (or align the code to the documented behavior).

Copilot uses AI. Check for mistakes.
Copy link
Contributor

@wbreza wbreza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review Summary

✅ What Looks Good

  • All claims verified against the codebase: WaitForDebugger signature, ErrDebuggerAborted, env var inheritance behavior, AZD_EXT_TIMEOUT default, optional env_name parameter
  • Well-organized with clear sections for debugging, env propagation, and error handling
  • Good code examples with practical usage patterns
  • Table of Contents properly updated

Findings Summary

Priority Count
🔴 Critical 1
Total 1

Overall Assessment: The documentation is thorough and well-structured. One factual error in the ServiceError struct needs fixing before merge. See inline comment.

```go
type ServiceError struct {
Message string // Human-readable error message
Details string // Additional error details
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[🔴 Critical] ServiceError struct fields are incorrect

The documented struct shows a Details field that doesn't exist in the actual code (pkg/azdext/extension_error.go:14-24), and omits the Suggestion field that does exist.

Actual struct:

type ServiceError struct {
    Message     string // Human-readable error message
    ErrorCode   string // Service error code (e.g., "Conflict", "NotFound")
    StatusCode  int    // HTTP status code (e.g., 409, 404, 500)
    ServiceName string // Service host/name for telemetry (e.g., "ai.azure.com")
    Suggestion  string // Optional user-facing remediation guidance
}

Consider replacing Details with Suggestion and updating the comment to describe its purpose (optional remediation guidance for the user).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update extension framework docs

6 participants